<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Canvas 生成验证码</title>
</head>
<body>
  <canvas id="canvas" width="120" height="40"></canvas>

  <script>

    function rn(min, max){
      return parseInt(Math.random() * (max - min) + min)
    }

    function rc(min, max){
      const r = rn(min, max)
      const g = rn(min, max)
      const b = rn(min, max)
      return `rgb(${r}, $(g), ${b})`
    }

    const w = 120
    const h = 40

    const canvas = document.querySelector('#canvas')
    const ctx = canvas.getContext('2d')
    ctx.beginPath()
    ctx.fillStyle = rc(180, 230)
    ctx.fillRect(0, 0, w, h)

  </script>
</body>
</html>